package com.yk;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CollectionsDemo {

    public static void main(String[] args) {

        ArrayList<String> list = new ArrayList<String>();
        Collections.addAll(list, "apple", "banana", "orange");
        list.forEach(System.out::println);
        System.out.println("-------------------------");
        //打乱集合的顺序
        Collections.shuffle(list);
        list.forEach(System.out::println);
        System.out.println("-------------------------");

        test1();
    }

    public static void test1() {
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        //按照倒序排序
        Collections.shuffle(list);
        list.forEach(System.out::println);
        Collections.sort(list,(o1, o2) -> {
            return o2 - o1;
        });
        System.out.println("---------------------------");
        list.forEach(System.out::println);
        //让学生实现compareble接口
        System.out.println("--------------------------");
        List<Student> students = new ArrayList<>();
        students.add(new Student("Tom", 80));
        students.add(new Student("Jerry", 90));
        students.add(new Student("Alice", 70));
        students.add(new Student("Bob", 85));
        Collections.sort(students);
        students.forEach(System.out::println);




    }
}
